package com.leetcode.math;

import java.util.Scanner;

public class RomanToInteger {

	public static void main(String[] args) {

		Scanner in=new Scanner(System.in);
		String s=in.nextLine();
		int k=romanToInt(s);
		System.out.println(k);
	}

	public static int romanToInt(String s) {

//		String[] romans={
//				"I","V","X","L","C","D","M"
//		};
//		int [] romanInt={
//				1,5,10,50,100,500,1000
//		};
		//I-1,V-5,X-10,L-50,C-100,D-500,M-1000
		if(s==null||s.isEmpty()) return 0;
		String[] strSplit=s.split("");
		int[] intSplit=new int[strSplit.length];
		for(int i=0;i<strSplit.length;i++){
			intSplit[i]=getInt(strSplit[i]);
		}
		int resultInt=0,i=1;
		for (i=1;i<intSplit.length-1;){
			if(intSplit[i]>=intSplit[i+1]){
				resultInt+=intSplit[i];
				i++;
				//if(i==intSplit.length-1) break;
			}else{
				resultInt+=intSplit[i+1]-intSplit[i];
				i+=2;
			}	
		}
		if(i==intSplit.length-1) resultInt+=intSplit[i];
//		if(intSplit[intSplit.length-2]<intSplit[intSplit.length-1])
//			
//				resultInt+=intSplit[intSplit.length-1]-intSplit[intSplit.length-2];
//		else
//			resultInt+=intSplit[intSplit.length-1]+intSplit[intSplit.length-2];
//		
		for(int k=0;k<strSplit.length;k++)
			System.out.println(strSplit[k]);
		return resultInt;
	}
	
	public static int getInt(String s){
	
		switch(s){
		case "I":return 1;
		case "V":return 5;
		case "X":return 10;
		case "L": return 50;
		case "C":return 100;
		case "D":return 500;
		case "M":return 1000;
		}
		return 0;
	}
}
